Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using catch after try #59847

Merged
merged 5 commits into from
Apr 13, 2019
Merged

Conversation

Kampfkarren
Copy link
Contributor

Part of #31436

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 10, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:0a0904ec:start=1554918550541482494,finish=1554918623685650324,duration=73144167830
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[01:07:44] .................................................................................................... 4800/5531
[01:07:48] .................................................................................................... 4900/5531
[01:07:52] .................................................................................................... 5000/5531
[01:07:57] .................................................................................................... 5100/5531
[01:08:00] ...........................................................................F........................ 5200/5531
[01:08:08] .................................................................................................... 5400/5531
[01:08:11] .....................................................................i.............................. 5500/5531
[01:08:12] ...............................
[01:08:12] failures:
[01:08:12] failures:
[01:08:12] 
[01:08:12] ---- [ui] ui/try-block/try-block-catch.rs stdout ----
[01:08:12] diff of stderr:
[01:08:12] 
[01:08:12] 1 error: `try {} catch` is not a valid syntax
[01:08:12] -   --> $DIR/try-block-catch.rs:8:4
[01:08:12] +   --> $DIR/try-block-catch.rs:8:7
[01:08:12] 3    |
[01:08:12] - LL |     } catch { }; //~ ERROR `try {} catch` is not a valid syntax
[01:08:12] + LL |     } catch { };
[01:08:12] 6    |
[01:08:12] 6    |
[01:08:12] 7    = help: try using `match` on the result of the `try` block instead
[01:08:12] 
[01:08:12] The actual stderr differed from the expected stderr.
[01:08:12] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-catch/try-block-catch.stderr
[01:08:12] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-catch/try-block-catch.stderr
[01:08:12] To update references, rerun the tests and pass the `--bless` flag
[01:08:12] To only update this specific test, also pass `--test-args try-block/try-block-catch.rs`
[01:08:12] error: 1 errors occurred comparing output.
[01:08:12] status: exit code: 1
[01:08:12] status: exit code: 1
[01:08:12] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/try-block/try-block-catch.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-catch/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition" "2018" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-catch/auxiliary" "-A" "unused"
[01:08:12] ------------------------------------------
[01:08:12] 
[01:08:12] ------------------------------------------
[01:08:12] stderr:
[01:08:12] stderr:
[01:08:12] ------------------------------------------
[01:08:12] {"message":"`try {} catch` is not a valid syntax","code":null,"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-catch.rs","byte_start":124,"byte_end":129,"line_start":8,"line_end":8,"column_start":7,"column_end":12,"is_primary":true,"text":[{"text":"    } catch { }; //~ ERROR `try {} catch` is not a valid syntax","highlight_start":7,"highlight_end":12}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using `match` on the result of the `try` block instead","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error: `try {} catch` is not a valid syntax\n  --> /checkout/src/test/ui/try-block/try-block-catch.rs:8:7\n   |\nLL |     } catch { }; //~ ERROR `try {} catch` is not a valid syntax\n   |       ^^^^^\n   |\n   = help: try using `match` on the result of the `try` block instead\n\n"}
[01:08:12] 
[01:08:12] ------------------------------------------
[01:08:12] 
[01:08:12] thread '[ui] ui/try-block/try-block-catch.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3425:9
---
[01:08:12] 
[01:08:12] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:516:22
[01:08:12] 
[01:08:12] 
[01:08:12] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:08:12] 
[01:08:12] 
[01:08:12] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:08:12] Build completed unsuccessfully in 0:04:46
[01:08:12] Build completed unsuccessfully in 0:04:46
[01:08:12] make: *** [check] Error 1
[01:08:12] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:003c9254
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed Apr 10 18:58:46 UTC 2019
---
travis_time:end:0c35c706:start=1554922728474844431,finish=1554922728480495949,duration=5651518
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0e1e06e5
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:093d47e4
travis_time:start:093d47e4
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:01fdecc8
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:059a92ca:start=1554923787358649464,finish=1554923865665391512,duration=78306742048
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[01:06:00] .................................................................................................... 4800/5531
[01:06:03] .................................................................................................... 4900/5531
[01:06:06] .................................................................................................... 5000/5531
[01:06:11] .................................................................................................... 5100/5531
[01:06:14] ...........................................................................F........................ 5200/5531
[01:06:21] .................................................................................................... 5400/5531
[01:06:24] .....................................................................i.............................. 5500/5531
[01:06:25] ...............................
[01:06:25] failures:
[01:06:25] failures:
[01:06:25] 
[01:06:25] ---- [ui] ui/try-block/try-block-catch.rs stdout ----
[01:06:25] diff of stderr:
[01:06:25] 
[01:06:25] 1 error: `try {} catch` is not a valid syntax
[01:06:25] 2   --> $DIR/try-block-catch.rs:8:7
[01:06:25] 3    |
[01:06:25] - LL |     } catch { }; //~ ERROR `try {} catch` is not a valid syntax
[01:06:25] + LL |     } catch { };
[01:06:25] 6    |
[01:06:25] 6    |
[01:06:25] 7    = help: try using `match` on the result of the `try` block instead
[01:06:25] 
[01:06:25] The actual stderr differed from the expected stderr.
[01:06:25] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-catch/try-block-catch.stderr
[01:06:25] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-catch/try-block-catch.stderr
[01:06:25] To update references, rerun the tests and pass the `--bless` flag
[01:06:25] To only update this specific test, also pass `--test-args try-block/try-block-catch.rs`
[01:06:25] error: 1 errors occurred comparing output.
[01:06:25] status: exit code: 1
[01:06:25] status: exit code: 1
[01:06:25] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/try-block/try-block-catch.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-catch/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition" "2018" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/try-block/try-block-catch/auxiliary" "-A" "unused"
[01:06:25] ------------------------------------------
[01:06:25] 
[01:06:25] ------------------------------------------
[01:06:25] stderr:
[01:06:25] stderr:
[01:06:25] ------------------------------------------
[01:06:25] {"message":"`try {} catch` is not a valid syntax","code":null,"level":"error","spans":[{"file_name":"/checkout/src/test/ui/try-block/try-block-catch.rs","byte_start":124,"byte_end":129,"line_start":8,"line_end":8,"column_start":7,"column_end":12,"is_primary":true,"text":[{"text":"    } catch { }; //~ ERROR `try {} catch` is not a valid syntax","highlight_start":7,"highlight_end":12}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"try using `match` on the result of the `try` block instead","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"error: `try {} catch` is not a valid syntax\n  --> /checkout/src/test/ui/try-block/try-block-catch.rs:8:7\n   |\nLL |     } catch { }; //~ ERROR `try {} catch` is not a valid syntax\n   |       ^^^^^\n   |\n   = help: try using `match` on the result of the `try` block instead\n\n"}
[01:06:25] 
[01:06:25] ------------------------------------------
[01:06:25] 
[01:06:25] thread '[ui] ui/try-block/try-block-catch.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3425:9
---
[01:06:25] 
[01:06:25] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:516:22
[01:06:25] 
[01:06:25] 
[01:06:25] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:06:25] 
[01:06:25] 
[01:06:25] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:06:25] Build completed unsuccessfully in 0:04:21
[01:06:25] Build completed unsuccessfully in 0:04:21
[01:06:25] make: *** [check] Error 1
[01:06:25] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:01e89238
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Wed Apr 10 20:24:20 UTC 2019
---
travis_time:end:0bef3624:start=1554927861563602999,finish=1554927861571259717,duration=7656718
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:048cfc5a
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0b488680
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@@ -3618,7 +3618,14 @@ impl<'a> Parser<'a> {
{
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
attrs.extend(iattrs);
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs))
if self.eat_keyword(keywords::Catch) {
Copy link
Contributor

@Centril Centril Apr 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be preferable to ban any form of try { ... } $ident { .. } from a perspective of having maximum flexibility in the future.

Copy link
Contributor Author

@Kampfkarren Kampfkarren Apr 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should those all suggest match instead, or should that just be catch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @estebank ^-- I would probably say yes, but that's more a diagnostics issue than future lang design flexibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking of the following case:

    let _ = try {
        true
    }
    let _ = ();

where the error is the lack of ;, which is why I'm a bit weary of suggesting the right syntax for every ident. The current output for this the following, which I feel doesn't hinder understanding more than complaining about an inexistent catch would:

error: expected one of `.`, `;`, `?`, or an operator, found `let`
 --> src/main.rs:7:5
  |
6 |     }
  |      - expected one of `.`, `;`, `?`, or an operator here
7 |     let _ = ();
  |     ^^^ unexpected token

src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser.rs Show resolved Hide resolved
@@ -3618,7 +3618,14 @@ impl<'a> Parser<'a> {
{
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
attrs.extend(iattrs);
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs))
if self.eat_keyword(keywords::Catch) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking of the following case:

    let _ = try {
        true
    }
    let _ = ();

where the error is the lack of ;, which is why I'm a bit weary of suggesting the right syntax for every ident. The current output for this the following, which I feel doesn't hinder understanding more than complaining about an inexistent catch would:

error: expected one of `.`, `;`, `?`, or an operator, found `let`
 --> src/main.rs:7:5
  |
6 |     }
  |      - expected one of `.`, `;`, `?`, or an operator here
7 |     let _ = ();
  |     ^^^ unexpected token

src/libsyntax/parse/parser.rs Show resolved Hide resolved
@Centril
Copy link
Contributor

Centril commented Apr 10, 2019

r? @estebank

@estebank
Copy link
Contributor

The only action item from me would be rewording the error message and maybe fleshing out the help. Other than that r=me.

@Kampfkarren
Copy link
Contributor Author

Out of the house right now so I'll work on all that when I can, thanks for the reviews!

@Kampfkarren
Copy link
Contributor Author

Tests passed @estebank

@Kampfkarren Kampfkarren reopened this Apr 11, 2019
@Kampfkarren
Copy link
Contributor Author

Kampfkarren commented Apr 11, 2019

Didn't realize I accidentally closed this, 🤦‍♂️

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Apr 11, 2019

📌 Commit 1156ce6 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 11, 2019
@Centril
Copy link
Contributor

Centril commented Apr 11, 2019

@estebank This still accepts try { ... } $ident { ... } where $ident != catch. I'm happy for this to happen in a follow up, but it still needs to happen... ^^

@Kampfkarren
Copy link
Contributor Author

@Centril I can do that in a separate PR later.

@Centril
Copy link
Contributor

Centril commented Apr 11, 2019

@Kampfkarren Excellent! Thank you.

@estebank
Copy link
Contributor

This still accepts try { ... } $ident { ... } where $ident != catch. I'm happy for this to happen in a follow up, but it still needs to happen...

It doesn't accept it, it just keeps the current

error: expected one of `.`, `;`, `?`, or an operator, found `$ident`

right?

@Kampfkarren
Copy link
Contributor Author

@estebank Yes, but I'm assuming he meant an explicit check against it for forwards compatibility?

@Centril
Copy link
Contributor

Centril commented Apr 12, 2019

right?

Not sure... I'll have a look on nightly once this is merged... :)

Centril added a commit to Centril/rust that referenced this pull request Apr 12, 2019
…bank

Error when using `catch` after `try`

Part of rust-lang#31436
bors added a commit that referenced this pull request Apr 13, 2019
Rollup of 8 pull requests

Successful merges:

 - #59781 (Remove check_match from const_eval)
 - #59820 (proc_macro: stop using LEB128 for RPC.)
 - #59846 (clarify what the item is in "not a module" error)
 - #59847 (Error when using `catch` after `try`)
 - #59859 (Suggest removing `?` to resolve type errors.)
 - #59862 (Tweak unstable diagnostic output)
 - #59866 (Recover from missing semicolon based on the found token)
 - #59892 (Impl RawFd conversion traits for WASI TcpListener, TcpStream and UdpSocket)

Failed merges:

r? @ghost
@bors bors merged commit 1156ce6 into rust-lang:master Apr 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants